package com.xinyun.server;

import com.xinyun.server.db.ElectricMeter;
import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by bubusy on 16/5/29.
 */
public class Test {

    public static void main(String[] args) throws Exception {
        String url = "jdbc:mysql://192.168.33.10:3306/dlxt";
        String user = "root";
        String password = "root";

        BasicDataSource basicDs = new BasicDataSource();
        basicDs.setUrl(url);
        basicDs.setUsername(user);
        basicDs.setPassword(password);
        DB.dataSource = basicDs;

        QueryRunner runner = new QueryRunner(DB.dataSource);

        Date boardTime = null;
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd H:m:s");
            boardTime = sdf.parse("2016-02-12 12:05:30");
        } catch (ParseException e) {
            e.printStackTrace();
        }

        String s_sql = "select * from z_phaethon_electricmeter where meter_id=?";

        BeanHandler<ElectricMeter> h = new BeanHandler<ElectricMeter>(ElectricMeter.class);

        ElectricMeter electricMeter = runner.query(s_sql, h, "012016042010060001");


        System.out.println(electricMeter.getMeter_id());

//        String sql = "insert into z_phaethon_meter_data " +
//                "(meter_id,DCU1,DCI1,DCU2,DCI2,DCU3,DCI3,DCU4,DCI4,ACUA,ACIA,ACUB,ACIB,ACUC,ACIC," +
//                "IVTemp,TotGenCap,IVStatus,IVError,IVMode,FR,IVRun,MonthGenCap,LastMonthGenCap,DayGenCap,LastDayGenCap," +
//                "PowerLimitPercent,ActivePower,ReactivePower,ApparentPower,PowerFactor,IVType,board_temp1,board_temp2," +
//                "current_leak,board_sum_gen,board_sum_use,board_time,created_at) " +
//                "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
//        runner.update(sql, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, boardTime, new Date());
    }
}
